package com.zhkj.txg.module.home.adapter

import android.widget.ImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.zhkj.lib.config.BASE_URL
import com.zhkj.lib.utils.ScreenUtil
import com.zhkj.txg.R
import com.zhkj.txg.module.home.entity.NavigationEntity
import com.zhkj.txg.utils.ImageUtils

class HomeCateAdapter2 :
    BaseQuickAdapter<NavigationEntity, BaseViewHolder>(R.layout.item_home_cate) {

    private var itemWidth: Int = 0

    override fun convert(helper: BaseViewHolder, item: NavigationEntity) {
        val imageView = helper.setText(R.id.tvCate, item.name).getView<ImageView>(R.id.ivCate)
        ImageUtils.loadCircleImage(
            context, imageView,
            if (item.image.startsWith("http")) item.image else BASE_URL + item.image
        )
    }

    override fun onItemViewHolderCreated(viewHolder: BaseViewHolder, viewType: Int) {
        itemWidth = (ScreenUtil.getScreenWidth(context) - ScreenUtil.dip(context, 120)) / 5
        viewHolder.itemView.layoutParams.width = itemWidth
    }
}